package com.lefu.es.system;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.NotificationManager;
import android.bluetooth.BluetoothGattCharacteristic;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lefu.es.application.IwellnessApplication;
import com.lefu.es.blenew.helper.BleHelper1;
import com.lefu.es.cache.CacheHelper;
import com.lefu.es.constant.AppData;
import com.lefu.es.constant.BluetoolUtil;
import com.lefu.es.constant.UtilConstants;
import com.lefu.es.db.RecordDao;
import com.lefu.es.entity.NutrientBo;
import com.lefu.es.entity.Records;
import com.lefu.es.entity.UserModel;
import com.lefu.es.event.DeletedRecordsEvent;
import com.lefu.es.event.NoRecordsEvent;
import com.lefu.es.service.ExitApplication;
import com.lefu.es.service.TimeService;
import com.lefu.es.service.UserService;
import com.lefu.es.util.FitbitHelper;
import com.lefu.es.util.GoogleFitUtils;
import com.lefu.es.util.LogUtil;
import com.lefu.es.util.MoveView;
import com.lefu.es.util.MyUtil;
import com.lefu.es.util.SPUtil;
import com.lefu.es.util.SharedPreferencesUtil;
import com.lefu.es.util.StringUtils;
import com.lefu.es.util.ToastUtils;
import com.lefu.es.util.UtilTooth;
import com.lefu.es.view.MyTextView5;
import com.lefu.es.view.guideview.HighLightGuideView;
import com.wellness.scale.R;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.File;
import java.io.Serializable;
import java.util.List;
import java.util.Locale;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.wellness.scale.R.id.cancle_datacbtn;
import static com.wellness.scale.R.id.save_databtn;

/*人体秤
* */
public class BodyScaleNewActivity extends BaseBleActivity {

    protected Dialog receiveDataDialog;
    @Bind(R.id.bluetooth_status)
    AppCompatTextView bluetoothStatusTx;
    @Bind(R.id.user_header)
    SimpleDraweeView userHeadImg;
    @Bind(R.id.user_name)
    AppCompatTextView userNameTx;
    @Bind(R.id.weith_value_tx)
    MyTextView5 weithValueTx;
    @Bind(R.id.weith_status)
    TextView weithStatus;
    @Bind(R.id.unti_tv)
    TextView unit_tv;
    /*体重
    * ---------*/
    @Bind(R.id.face_img_weight)
    ImageView face_img_weight;
    @Bind(R.id.face_img_weight_ll)
    LinearLayout face_img_weight_ll;
    @Bind(R.id.weight_critical_point1)
    TextView weight_critical_point1;
    @Bind(R.id.weight_critical_point2)
    TextView weight_critical_point2;
    @Bind(R.id.biaoz)
    AppCompatTextView biaoz;
    @Bind(R.id.weight_index_tx)
    AppCompatTextView weightIndex;
    @Bind(R.id.status_bar2)
    RelativeLayout status_bar2;
    @Bind(R.id.weight_jiantou)
    AppCompatImageView weight_jiantou;
    /*BMI
    *-----------------
     */
    @Bind(R.id.face_img_bmi)
    ImageView face_img_bmi;
    @Bind(R.id.face_img_bmi_ll)
    LinearLayout face_img_bmi_ll;
    @Bind(R.id.bmi_critical_point1)
    TextView bmi_critical_point1;
    @Bind(R.id.bmi_critical_point2)
    TextView bmi_critical_point2;
    @Bind(R.id.bmi_critical_point3)
    TextView bmi_critical_point3;
    @Bind(R.id.bmi_biaoz)
    AppCompatTextView bmi_biaoz;
    @Bind(R.id.bmi_index_tx)
    AppCompatTextView bmiIndex;
    @Bind(R.id.status_bar_bmi)
    RelativeLayout status_bar_bmi;
    @Bind(R.id.bmi_jiantou)
    AppCompatImageView bmi_jiantou;
    @Bind(R.id.targe_tx)
    TextView targetTx;
    @Bind(R.id.blue_img)
    ImageView blue_img;
    List<UserModel> babys = null;
    private boolean isActivityShow = false;
    private UserService uservice;
    private TextView tv_comp;
    private TextView tv_comp_bmi;
    private TextView tv_comp_weight_desc;
    private TextView tv_comp_weight_desc1;
    private TextView tv_comp_bmi_desc1;
    private RelativeLayout setting_menu;
    private View.OnClickListener imgOnClickListener = new View.OnClickListener() {
        @SuppressWarnings("deprecation")
        public void onClick(View v) {
            switch (v.getId()) {
                case cancle_datacbtn:
                    IwellnessApplication.dilogDate = System.currentTimeMillis();
                    if (null != receiveDataDialog) receiveDataDialog.dismiss();
                    receiveDataDialog = null;
                    try {
                        Records lastRecords = recordService.findLastRecords(UtilConstants.CURRENT_USER.getId(), "ce");
                        localData(lastRecords, UtilConstants.CURRENT_USER);
                    } catch (Exception e) {
                        LogUtil.e("*****Exception e-->"+e.getMessage());
                    }
                    break;
                case save_databtn:
                    IwellnessApplication.dilogDate = System.currentTimeMillis();
                    try {
                        AppData.hasCheckData = true;
                        if (!BluetoolUtil.bleflag)
                            TimeService.setIsdoing(true);
                        if (null != receiveRecod && null != receiveRecod.getScaleType()) {
                            float compare = 0;
                            if (!TextUtils.isEmpty(receiveRecod.getCompareRecord()) &&
                                    !"null".equals(receiveRecod.getCompareRecord())) {
                                compare = Float.parseFloat(receiveRecod.getCompareRecord());
                            }
                            LogUtil.e("****与上次数据对比相差值***compare-->" + compare);
                            if (Math.abs(compare) >= 3) {
                                askForSaveExceptionData();
                                //dialogForBodyScale(getString(R.string.receive_data_waring), v.getId());
                                if (null != receiveDataDialog) receiveDataDialog.dismiss();
                                receiveDataDialog = null;
                            } else {
                                if (UtilConstants.KITCHEN_SCALE.equals(UtilConstants.CURRENT_SCALE)) {
                                    NutrientBo nutrient = null;
                                    if (!TextUtils.isEmpty(receiveRecod.getRphoto())) {
                                        nutrient = CacheHelper.queryNutrientsByName(receiveRecod.getRphoto());
                                    }
                                    RecordDao.dueKitchenDate2(recordService, receiveRecod, nutrient);
                                } else {
                                    RecordDao.handleData2(recordService, receiveRecod);
                                    FitbitHelper.getInstance().postWeightAndFatData(receiveRecod);
                                }
                                saveDataCallBack(receiveRecod);
                                if (!BluetoolUtil.bleflag) {
                                    TimeService.setIsdoing(false);
                                }
                                if (null != receiveDataDialog) receiveDataDialog.dismiss();
                                receiveDataDialog = null;
                                receiveRecod = null;
                            }
                        }
                    } catch (Exception e) {
                        LogUtil.e("****保存用户测量数据异常 e-->"+e.getMessage());
                    }
                    break;
                default:
            }
        }
    };

    private RelativeLayout history_menu;
    private Button cancleBtn, saveBtn;
    Handler handler = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 0:
                    Records data = (Records) msg.obj;
                    LogUtil.e("***计算时间差****");
                    long date1 = IwellnessApplication.dilogDate;
                    LogUtil.e("****上次的时间是-->" + date1);
                    long dateCom = System.currentTimeMillis() - date1;
                    LogUtil.e("****时间差是-->" + dateCom / 1000 + "秒");
                    if ((dateCom / 1000) < 6) {
                        return;
                    }
                    if (null != data && null != data.getReceiveMsg() &&
                            RecordDao.isLockData(data.getReceiveMsg()) &&
                            data.getReceiveMsg().length() == "ce0000e01500000000003b".length()) {
                        playSound();
                        localData(data, UtilConstants.CURRENT_USER);
                        showReceiveDataDialog();
                    }
                    break;
                case 3:
                    data = (Records) msg.obj;
                    if (null != data) {
                        playSound();
                        localData(data, UtilConstants.CURRENT_USER);
                        showReceiveDataDialog();
                    }
                    break;
                case 1:

                    break;
                case 5:
                    /* 退出 */
                    exit();
                    ExitApplication.getInstance().exit(BodyScaleNewActivity.this);
                    break;
                case UtilConstants.scaleChangeMessage:
                    /*保存秤类型*/
                    if (UtilConstants.su == null) {
                        UtilConstants.su = new SharedPreferencesUtil(LoadingActivity.mainActivty);
                    }
                    UtilConstants.su.editSharedPreferences("lefuconfig", "scale", UtilConstants.CURRENT_SCALE);
                    /*保存用户信息*/
                    try {
                        uservice.update(UtilConstants.CURRENT_USER);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    /*跳转*/
                    ExitApplication.getInstance().exit(BodyScaleNewActivity.this);
                    Intent intent = new Intent();
                    intent.setClass(BodyScaleNewActivity.this, LoadingActivity.class);
                    BodyScaleNewActivity.this.startActivity(intent);
                    break;
                default:

            }
        }

    };
    private TextView textView1;

    private TextView textView2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_body_scale_new);
        String date = (String) SPUtil.get(BodyScaleNewActivity.this, "dialogdate", "0");
        long date1 = Long.valueOf(date);
        IwellnessApplication.dilogDate = date1;
        LogUtil.e("===IwellnessApplication.dilogDate:" + IwellnessApplication.dilogDate);
        tv_comp = (TextView) findViewById(R.id.tv_comp);
        tv_comp_bmi = (TextView) findViewById(R.id.tv_comp_bmi);
        tv_comp_weight_desc = (TextView) findViewById(R.id.tv_comp_weight_desc);
        tv_comp_weight_desc1 = (TextView) findViewById(R.id.tv_comp_weight_desc1);
        tv_comp_bmi_desc1 = (TextView) findViewById(R.id.tv_comp_bmi_desc1);
        setting_menu = (RelativeLayout) findViewById(R.id.setting_menu);
        history_menu = (RelativeLayout) findViewById(R.id.history_menu);
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
        uservice = new UserService(this);
        if (isZh()) {
            biaoz.setVisibility(View.VISIBLE);
            bmi_biaoz.setVisibility(View.VISIBLE);
        }
        initView();
        ExitApplication.getInstance().addActivity(this);
        /*boolean bindStatus = AppData.checkBindStatus();
        if (!bindStatus && UtilConstants.isFirsShow == 0) {
            bindAltert();
            UtilConstants.isFirsShow = 1;
        }*/
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void updateConnectionState(int resourceId) {
        switch (resourceId) {
            case R.string.disconnected:
                bluetoothStatusTx.setVisibility(View.GONE);
                blue_img.setVisibility(View.GONE);
                break;

            case R.string.connected:
                bluetoothStatusTx.setVisibility(View.VISIBLE);
                blue_img.setVisibility(View.VISIBLE);
                break;
            default:
        }
    }

    @Override
    public void discoverBleService() {
        ToastUtils.ToastCenter(BodyScaleNewActivity.this, getString(R.string.scale_paired_success));
        if (null != mDeviceName && (mDeviceName.toLowerCase().startsWith("heal"))
                || null != mDeviceName && (mDeviceName.toLowerCase().startsWith("smart")
                || (null != mDeviceName && mDeviceName.equals(AppData.LF_SCALE)))) {
            try {
                if (null != mBluetoothLeService) {
                    final BluetoothGattCharacteristic characteristic =
                            mBluetoothLeService.getCharacteristicNew(mBluetoothLeService.getSupportedGattServices(), "fff4");
                    mBluetoothLeService.setCharacteristicIndiacate(characteristic, true); //开始监听通道
                    //发送用户组数据
                    String unit = "00";
                    if (UtilConstants.CURRENT_USER.getDanwei().equals(UtilConstants.UNIT_ST)) {
                        unit = "02";
                    } else if (UtilConstants.CURRENT_USER.getDanwei().equals(UtilConstants.UNIT_LB)) {
                        unit = "01";
                    } else {
                        unit = "00";
                    }
                    // 获取用户组
                    String p = UtilConstants.CURRENT_USER.getGroup().replace("P", "0");
                    // 获取 校验位
                    String xor = Integer.toHexString(StringUtils.hexToTen("fd") ^ StringUtils.hexToTen("37") ^ StringUtils.hexToTen(unit) ^ StringUtils.hexToTen(p));
                    LogUtil.e("***发送新称数据：" + "fd37" + unit + p + "000000000000" + xor);
                    // 发送数据
                    BleHelper1.getInstance().sendDateToScale1(mBluetoothLeService, "fd37" + unit + p + "000000000000" + xor);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (mDeviceName != null && mDeviceName.toLowerCase().startsWith("yu")) {
            try {
                if (null != mBluetoothLeService) {
                    final BluetoothGattCharacteristic characteristic = mBluetoothLeService.getCharacteristicNew(mBluetoothLeService.getSupportedGattServices(), "2a9c");
                    mBluetoothLeService.setCharacteristicIndiacate(characteristic, true); //开始监听通道
                    //发送用户组数据
                    String unit = "00";
                    if (UtilConstants.CURRENT_USER.getDanwei().equals(UtilConstants.UNIT_ST)) {
                        unit = "02";
                    } else if (UtilConstants.CURRENT_USER.getDanwei().equals(UtilConstants.UNIT_LB)) {
                        unit = "01";
                    } else {
                        unit = "00";
                    }
                    // 获取用户组
                    String p = UtilConstants.CURRENT_USER.getGroup().replace("P", "0");
                    // 获取 校验位
                    String xor = Integer.toHexString(StringUtils.hexToTen("fd")^StringUtils.hexToTen("37")^StringUtils.hexToTen(unit) ^ StringUtils.hexToTen(p));
                    LogUtil.e("****发送新称数据：" + "fd37" + unit + p + "000000000000" + xor);
                    // 发送数据
                    BleHelper1.getInstance().sendDateToScale(mBluetoothLeService, "fd37" + unit + p + "000000000000" + xor);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            BleHelper1.getInstance().sendDateToScale(mBluetoothLeService, MyUtil.getUserInfo());
        }
    }

    @Override
    public void receiveBleData(String readMessage, String mac, String deviceName) {
        if (!isActivityShow) return;
        /****兼容旧版本**起*/
        if (readMessage.startsWith("0306")) {
            if ((System.currentTimeMillis() - UtilConstants.receiveDataTime > 1000) && null == receiveDataDialog) {
                UtilConstants.receiveDataTime = System.currentTimeMillis();
                LogUtil.e("*****接下来收到的数据要兼容旧版本*readMessage**" + readMessage);
                UtilConstants.CURRENT_SCALE = UtilConstants.BODY_SCALE;
                UtilConstants.CURRENT_USER.setScaleType(UtilConstants.CURRENT_SCALE);
                receiveRecod = MyUtil.parseZuKangMessage(this.recordService, readMessage, UtilConstants.CURRENT_USER);
                LogUtil.e("*****receiveRecord***" + receiveRecod);
                Message msg1 = handler.obtainMessage(3);
                msg1.obj = receiveRecod;
                handler.sendMessage(msg1);
            }
            return;
        }
        /****兼容旧版本**终*/
        if (!TextUtils.isEmpty(mac)) {
            mDeviceAddress = mac;
        }
        if (!TextUtils.isEmpty(deviceName)) {
            mDeviceName = deviceName;
        }
        System.out.println("检测读取到数据：" + readMessage);
        if (readMessage != null && readMessage.length() == 40) {
            readMessage = readMessage.substring(0, 22);
            LogUtil.e("****sub后的-->" + readMessage);
        }
        //测脂错误
        if (readMessage.startsWith("cb") || readMessage.startsWith("ca")) {

        } else {
            if (TextUtils.isEmpty(readMessage) || readMessage.length() < 10 || !mActivty) return;
            if (readMessage.equals(UtilConstants.ERROR_CODE)) {
                if (UtilConstants.CURRENT_USER.getDanwei().equals(UtilConstants.UNIT_ST) || UtilConstants.CURRENT_USER.getDanwei().equals(UtilConstants.UNIT_LB)) {
                    Toast.makeText(BodyScaleNewActivity.this, getString(R.string.user_data_error), Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(BodyScaleNewActivity.this, getString(R.string.user_data_error_lb), Toast.LENGTH_LONG).show();
                }
                return;
            } else if (readMessage.equals(UtilConstants.ERROR_CODE_TEST)) {
                Toast.makeText(BodyScaleNewActivity.this, getString(R.string.scale_measurement_error), Toast.LENGTH_LONG).show();
                return;
            }
        }

        //秤和人体参数不匹配
        if (readMessage.startsWith("cb") || readMessage.startsWith("ca")) {

        } else {
            if (!ageError) {
                if (UtilConstants.CURRENT_USER.getAgeYear() < 10 || UtilConstants.CURRENT_USER.getBheigth() < 100) {
                    if (UtilConstants.CURRENT_USER.getDanwei().equals(UtilConstants.UNIT_KG)) {
                        showAgeOrHeightAlertDailog(getString(R.string.age_error_4));
                    } else {
                        showAgeOrHeightAlertDailog(getString(R.string.age_error_6));
                    }
                    return;
                }
            }
        }
        //处理不同类型的秤

        boolean newScale = false;
        try {
            if ((readMessage.startsWith("0306"))) {//阿里秤
                newScale = true;
                UtilConstants.CURRENT_SCALE = UtilConstants.BODY_SCALE;
            } else {
                newScale = false;


                /** 称类型判断 */
                String choice_scale = "";
                if ((readMessage.toLowerCase().startsWith(UtilConstants.BODY_SCALE))) {
                    choice_scale = UtilConstants.BODY_SCALE;
                } else if ((readMessage.toLowerCase().startsWith(UtilConstants.BATHROOM_SCALE))) {
                    choice_scale = UtilConstants.BATHROOM_SCALE;
                } else if ((readMessage.toLowerCase().startsWith(UtilConstants.BABY_SCALE))) {
                    choice_scale = UtilConstants.BABY_SCALE;
                } else if ((readMessage.toLowerCase().startsWith(UtilConstants.KITCHEN_SCALE))) {
                    choice_scale = UtilConstants.KITCHEN_SCALE;
                }
                UtilConstants.CURRENT_SCALE = choice_scale;
            }
            LogUtil.e("****mDeviceName:" + mDeviceName);
            if (null != mDeviceName && mDeviceName.toLowerCase().startsWith(UtilConstants.DLscaleName) || (null != mDeviceName && mDeviceName.toLowerCase().startsWith("heal")) && readMessage.length() == "cf9015d6153a353b0000bd".length()) { //新的DL Scale
                LogUtil.e("****处理数据:" + readMessage);
                if (RecordDao.isLockData(readMessage)) {
                    if ((System.currentTimeMillis() - UtilConstants.receiveDataTime > 1500) && null == receiveDataDialog) {
                        UtilConstants.receiveDataTime = System.currentTimeMillis();
                        dueDate(readMessage, 3);
                    }
                } else {
                    dueDate(readMessage, 2);
                }
            } else {
                /**判断是不是两次连续的数据*/
                if (readMessage.length() > 31 && !mDeviceName.toLowerCase().startsWith(UtilConstants.DLscaleName) && (System.currentTimeMillis() - UtilConstants.receiveDataTime > 1000)) {
                    UtilConstants.receiveDataTime = System.currentTimeMillis();

                    if (newScale) {
                            /*脂肪秤*/
                        UtilConstants.CURRENT_SCALE = UtilConstants.BODY_SCALE;
                        UtilConstants.CURRENT_USER.setScaleType(UtilConstants.CURRENT_SCALE);
                        dueDate(readMessage, 1);
                    } else {
                        if (readMessage.equals(UtilConstants.ERROR_CODE)) {
                            if (UtilConstants.CURRENT_USER.getDanwei().equals(UtilConstants.UNIT_ST) || UtilConstants.CURRENT_USER.getDanwei().equals(UtilConstants.UNIT_LB)) {
                                Toast.makeText(BodyScaleNewActivity.this, getString(R.string.user_data_error), Toast.LENGTH_LONG).show();
                            } else {
                                Toast.makeText(BodyScaleNewActivity.this, getString(R.string.user_data_error_lb), Toast.LENGTH_LONG).show();
                            }
                            return;
                        } else if (readMessage.equals(UtilConstants.ERROR_CODE_TEST)) {
                            Toast.makeText(BodyScaleNewActivity.this, getString(R.string.scale_measurement_error), Toast.LENGTH_LONG).show();
                            return;
                        }
                            /*显示称类型错误*/
                        if (!readMessage.startsWith(UtilConstants.BATHROOM_SCALE) && readMessage.length() > 31) {
                                /*跳转到制定的秤界面*/
                            if (readMessage.startsWith(UtilConstants.BODY_SCALE)) {
                                    /*脂肪秤*/
                                UtilConstants.CURRENT_SCALE = UtilConstants.BODY_SCALE;
                                UtilConstants.CURRENT_USER.setScaleType(UtilConstants.CURRENT_SCALE);
                                    /*保存测量数据*/
                                RecordDao.dueDate(recordService, readMessage);
                            } else if (readMessage.startsWith(UtilConstants.BABY_SCALE)) {
                                    /*婴儿秤*/
                                UtilConstants.CURRENT_SCALE = UtilConstants.BABY_SCALE;
                                UtilConstants.CURRENT_USER.setScaleType(UtilConstants.CURRENT_SCALE);
                                    /*保存测量数据*/
                                RecordDao.dueDate(recordService, readMessage);
                            } else if (readMessage.startsWith(UtilConstants.KITCHEN_SCALE)) {
                                    /* 厨房秤 */
                                UtilConstants.CURRENT_SCALE = UtilConstants.KITCHEN_SCALE;
                                UtilConstants.CURRENT_USER.setScaleType(UtilConstants.CURRENT_SCALE);
                                    /* 保存测量数据 */
                                RecordDao.dueKitchenDate(recordService, readMessage, null);
                            }
                            handler.sendEmptyMessage(UtilConstants.scaleChangeMessage);
                            return;
                        }
                        if (readMessage.equals(UtilConstants.ERROR_CODE_GETDATE)) {
                            openErrorDialog("2");
                            return;
                        }
                        if ((readMessage.startsWith("c") && readMessage.length() > 31)) {
                            dueDate(readMessage, 0);
                        }
                    }
                }
            }

        } catch (Exception e) {
            LogUtil.e("****解析数据异常" + e.getMessage());
        }
    }

    /**
     * 数据处理
     *
     * @param readMessage
     * @param i
     */
    private void dueDate(String readMessage, int i) {
        if (0 == i) {//旧秤
            receiveRecod = MyUtil.parseMessage(this.recordService, readMessage);

            Message msg1 = handler.obtainMessage(3);
            msg1.obj = receiveRecod;
            handler.sendMessage(msg1);
        } else if (1 == i) {//阿里秤
            receiveRecod = MyUtil.parseZuKangMeaage(this.recordService, readMessage, UtilConstants.CURRENT_USER);
            Message msg1 = handler.obtainMessage(3);
            msg1.obj = receiveRecod;
            handler.sendMessage(msg1);
        } else if (2 == i) {//新称过程数据
            LogUtil.e("****新称过程数据====UtilConstants.CURRENT_USER.getDanwei()===" + UtilConstants.CURRENT_USER.getDanwei());
            MyUtil.setProcessWeightData(BodyScaleNewActivity.this, readMessage, weithValueTx, UtilConstants.CURRENT_USER.getDanwei(), false);
        } else if (3 == i) {//新秤锁定数据
            receiveRecod = MyUtil.parseDLScaleMessage(this.recordService, readMessage, UtilConstants.CURRENT_USER);
            if (null != receiveRecod) {
                receiveRecod.setReceiveMsg(readMessage);
            }
            Message msg1 = handler.obtainMessage(0);
            msg1.obj = receiveRecod;
            handler.sendMessage(msg1);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        LogUtil.e("****onActivityResult==" + resultCode);
        if (resultCode == 103) {
            Bundle loginBundle = data.getExtras();
            if (null != loginBundle) {
                Serializable serializable = loginBundle.getSerializable("user");
                if (null != serializable) {
                    UserModel user = (UserModel) serializable;
                    //保存用户
                    UtilConstants.CURRENT_USER = user;
                    UtilConstants.SELECT_USER = UtilConstants.CURRENT_USER.getId();
                    System.out.println("当前用户称类型：" + UtilConstants.CURRENT_SCALE);
                    if (null != UtilConstants.CURRENT_USER && null != UtilConstants.CURRENT_USER.getDanwei() && !"".equals(UtilConstants.CURRENT_USER.getDanwei())) {
                        if (null != UtilConstants.su) {
                            UtilConstants.su.editSharedPreferences("lefuconfig", "unit", UtilConstants.CURRENT_USER.getDanwei());
                            UtilConstants.su.editSharedPreferences("lefuconfig", "user", UtilConstants.CURRENT_USER.getId());
                        }
                    }
                    RecordDao.handleData2(recordService, receiveRecod);
                    FitbitHelper.getInstance().postWeightAndFatData(receiveRecod);
                    initView();
                    receiveRecod = null;
                }
            }
        } else if (requestCode == 1) {
            LogUtil.e("****从设置界面返回");
            initView();
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        isActivityShow = false;
/*

        if (null != mBluetoothLeService) {
            mScanner.stopScan();
            mBluetoothLeService.disconnect();
        }
*/

    }

    @Override
    protected void onResume() {
        super.onResume();
        isActivityShow = true;
        startScanBLE();
        boolean bindStatus = AppData.checkBindStatus();
        if (!bindStatus && UtilConstants.isFirsShow == 0) {
            bindAltert();
            UtilConstants.isFirsShow = 1;
        }
    }

    @Override
    protected void saveDataCallBack(Records records) {
        if (UtilConstants.CURRENT_USER.getGroup().equals("P1")) {
            GoogleFitUtils googleFitUtils = new GoogleFitUtils();
            if (googleFitUtils.isOpenGoogleFit(BodyScaleNewActivity.this)) {
                googleFitUtils.insertData(BodyScaleNewActivity.this, records.getRweight());
            }
        }
        if (records.getScaleType().startsWith(UtilConstants.BODY_SCALE)) {
                                    /*脂肪秤*/
            UtilConstants.CURRENT_SCALE = UtilConstants.BODY_SCALE;
            UtilConstants.CURRENT_USER.setScaleType(UtilConstants.CURRENT_SCALE);
            handler.sendEmptyMessage(UtilConstants.scaleChangeMessage);
        } else if (records.getScaleType().startsWith(UtilConstants.BABY_SCALE)) {
                                    /*婴儿秤*/
            UtilConstants.CURRENT_SCALE = UtilConstants.BABY_SCALE;
            UtilConstants.CURRENT_USER.setScaleType(UtilConstants.CURRENT_SCALE);
                                    /*保存测量数据*/
            handler.sendEmptyMessage(UtilConstants.scaleChangeMessage);
        } else if (records.getScaleType().startsWith(UtilConstants.KITCHEN_SCALE)) {
                                    /* 厨房秤 */
            UtilConstants.CURRENT_SCALE = UtilConstants.KITCHEN_SCALE;
            UtilConstants.CURRENT_USER.setScaleType(UtilConstants.CURRENT_SCALE);
            handler.sendEmptyMessage(UtilConstants.scaleChangeMessage);
        } else {
            localData(records, UtilConstants.CURRENT_USER);
            initBodyBar(UtilConstants.CURRENT_USER, records);
        }
    }

    private boolean isZh() {
        Locale locale = getResources().getConfiguration().locale;
        String language = locale.getLanguage();
        if (language.endsWith("zh"))
            return true;
        else
            return false;
    }

    private void initView() {
        LogUtil.e("****初始化view****");
        UtilConstants.SELECT_SCALE = UtilConstants.BATHROOM_SCALE;
        if (null != UtilConstants.CURRENT_USER) {
            userNameTx.setText(UtilConstants.CURRENT_USER.getUserName());
            LogUtil.e("****加载用户的头象：" + UtilConstants.CURRENT_USER.getPer_photo());
            if (!TextUtils.isEmpty(UtilConstants.CURRENT_USER.getPer_photo())) {
                userHeadImg.setImageURI(Uri.fromFile(new File(UtilConstants.CURRENT_USER.getPer_photo())));
            } else {
                if ("1".equals(UtilConstants.CURRENT_USER.getSex())) {
                    userHeadImg.setImageResource(R.drawable.nan);
                } else {
                    userHeadImg.setImageResource(R.drawable.nu);
                }
            }
            if (UtilConstants.CURRENT_USER.getDanwei().equals(UtilConstants.UNIT_LB)
                    || UtilConstants.CURRENT_USER.getDanwei().equals(UtilConstants.UNIT_FATLB)
                    || UtilConstants.CURRENT_USER.getDanwei().equals(UtilConstants.UNIT_ST)) {
                targetTx.setText(UtilTooth.kgToLB_ForFatScale(UtilConstants.CURRENT_USER.getTargweight()) + "lb");
            } else {
                targetTx.setText(UtilTooth.keep1Point3(UtilConstants.CURRENT_USER.getTargweight()) + "kg");
            }
            try {
                Records lastRecords = recordService.findLastRecords(UtilConstants.CURRENT_USER.getId(), "ce");
                localData(lastRecords, UtilConstants.CURRENT_USER);
                initBodyBar(UtilConstants.CURRENT_USER, lastRecords);

                if (TextUtils.isEmpty(UtilConstants.FIRST_INSTALL_SETTING_PAGER)) {
                    showSettingTipMask();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 绑定提示
     */
    private void bindAltert() {
        // 初始化自定义布局参数
        LayoutInflater layoutInflater = getLayoutInflater();
        // 为了能在下面的OnClickListener中获取布局上组件的数据，必须定义为final类型.
        View customLayout = layoutInflater.inflate(R.layout.activity_receive_alert2,
                (ViewGroup) findViewById(R.id.receiveDataDialog));
        cancleBtn = (Button) customLayout.findViewById(R.id.cancle_datacbtn);
        saveBtn = (Button) customLayout.findViewById(R.id.save_databtn);
        textView1 = (TextView) customLayout.findViewById(R.id.textView1);
        textView2 = (TextView) customLayout.findViewById(R.id.textView2);
        textView1.setText(R.string.bind_tishi_4);
        textView2.setText(R.string.bind_tishi_1);
        cancleBtn.setText(R.string.no_btn);
        saveBtn.setText(R.string.yes_btn);

        cancleBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                receiveDataDialog.dismiss();
            }
        });
        saveBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                receiveDataDialog.dismiss();
                Intent intent = new Intent(BodyScaleNewActivity.this, BindScaleActivity.class);
                startActivity(intent);
            }
        });
        receiveDataDialog = new Dialog(this, R.style.dialog);
        receiveDataDialog.setContentView(customLayout);
        receiveDataDialog.setCanceledOnTouchOutside(false);
        receiveDataDialog.show();
        Window window = receiveDataDialog.getWindow();
        window.setGravity(Gravity.CENTER); // 此处可以设置dialog显示的位置
        window.setWindowAnimations(R.style.mystyle); // 添加动画
    }

    /**
     * 初始化 圆圈参数
     *
     * @param
     */
    private void localData(Records record, UserModel user) {
        if (null == user) return;
        if (user.getDanwei().equals(UtilConstants.UNIT_ST)) {
            if (UtilConstants.CURRENT_SCALE.equals(UtilConstants.BODY_SCALE)) {
                String[] tempS = {"0", "0"};
                if (null != record) tempS = UtilTooth.kgToStLbForScaleFat2(record.getRweight());
                weithValueTx.setTexts(tempS[0], tempS[1]);
                if (null != unit_tv) {
                    unit_tv.setText(this.getText(R.string.stlb_danwei));
                }
            } else {
                if (null != record) {
                    weithValueTx.setTexts(UtilTooth.kgToStLb(record.getRweight()), null);
                } else {
                    weithValueTx.setTexts("0", null);
                }
                if (null != unit_tv) {
                    unit_tv.setText(this.getText(R.string.stlb_danwei));
                }
            }
        } else if (user.getDanwei().equals(UtilConstants.UNIT_LB) || user.getDanwei().equals(UtilConstants.UNIT_FATLB)) {
            if (null != record) {
                weithValueTx.setTexts(UtilTooth.kgToLB_ForFatScale(record.getRweight()), null);
            } else {
                weithValueTx.setTexts("0.0", null);
            }
            if (null != unit_tv) {
                unit_tv.setText(this.getText(R.string.lb_danwei));
            }
        } else {
            if (null != record) {
                weithValueTx.setTexts(UtilTooth.keep1Point(record.getRweight()), null);
            } else {
                weithValueTx.setTexts("0.0", null);
            }
            if (null != unit_tv) {
                unit_tv.setText(this.getText(R.string.kg_danwei));
            }
        }
        String sex = user.getSex();
        if (TextUtils.isEmpty(sex) || "null".equalsIgnoreCase(sex)) sex = "1";
        int gender = Integer.parseInt(sex);
        weithStatus.setText(MoveView.weightString(gender, user.getBheigth(),
                null == record ? 0f : record.getRweight(), this));
    }

    /**
     * 初始化界面所有的进度条
     *
     * @param record
     */
    public void initBodyBar(UserModel user, Records record) {
        if (null != user) {
            String sex = user.getSex();
            if (TextUtils.isEmpty(sex) || "null".equalsIgnoreCase(sex)) sex = "1";
            int gender = Integer.parseInt(sex);
            // 体重
            float weight = (null == record ? 0f : record.getRweight());
            if (user.getDanwei().equals(UtilConstants.UNIT_LB)
                    || user.getDanwei().equals(UtilConstants.UNIT_FATLB)
                    || user.getDanwei().equals(UtilConstants.UNIT_ST)) {
                weightIndex.setText(UtilTooth.kgToLB_ForFatScale(weight) + "lb");
            } else {
                weightIndex.setText(UtilTooth.keep1Point(weight) + "kg");
            }
            MoveView.weight(BodyScaleNewActivity.this, face_img_weight_ll, face_img_weight,
                    weight_critical_point1, weight_critical_point2, biaoz,
                    gender, user.getBheigth(), weight, user.getDanwei());
            // BMI
            float bmi = 0.0f;
            if (null != record) {
                bmi = UtilTooth.myround(UtilTooth.countBMI2(record.getRweight(), (user.getBheigth() / 100)));
                compData(record);
                bmiIndex.setText(UtilTooth.keep1Point(bmi));
                MoveView.bmi(BodyScaleNewActivity.this, face_img_bmi_ll, face_img_bmi,
                        bmi_critical_point1, bmi_critical_point2, bmi_critical_point3, bmi_biaoz, bmi);
            }
            String comBmiStr = "";
            if (record == null) return;
            float comBmi = record.getComBmi();
            if (comBmi >= 0) {
                comBmiStr = getString(R.string.shangshen) + comBmi + "!";
            } else {
                comBmiStr = getString(R.string.xiajiang) + Math.abs(comBmi) + "!";
            }
            tv_comp_bmi_desc1.setText(getString(R.string.tishi_bmi) + "" + (record.getRbmi())
                    + "," + getString(R.string.com_fat_desc6) + "," + (comBmiStr));
            //体重建议
            int weightStaus = MoveView.weightInt(gender, user.getBheigth(), null == record ? 0f : record.getRweight());

            if (weightStaus == 1) {
                tv_comp_weight_desc.setText(getString(R.string.com_weight_piandi_desc));
            } else if (weightStaus == 2) {
                tv_comp_weight_desc.setText(getString(R.string.com_weight_biaozhun_desc));
            } else {
                tv_comp_weight_desc.setText(getString(R.string.com_weight_piangao_desc));
            }
            float weight1 = record.getRweight();
            String weight1Str = "";
            if (user.getDanwei().equals("kg")) {
                weight1Str = UtilTooth.keep1Point(weight1) + "kg" + ",";
            } else {
                weight1Str = UtilTooth.kgToLB_ForFatScale(weight1) + "lb" + ",";
            }
            //当前体重与上次的对比
            String comWeightStr = "";
            float comWeight = Float.parseFloat(record.getCompareRecord());
            if (user.getDanwei().equals("kg")) {
                comWeightStr = comWeight + "kg";
            } else {
                comWeightStr = UtilTooth.kgToLB(comWeight) + "lb";
            }
            if (comWeight >= 0) {
                comWeightStr = getString(R.string.shangshen) + comWeightStr + "!";
            } else {
                if (user.getDanwei().equals("kg")) {
                    comWeightStr = getString(R.string.xiajiang) + UtilTooth.keep1Point(Math.abs(comWeight)) + "kg!";
                } else {
                    comWeightStr = getString(R.string.xiajiang) + UtilTooth.kgToLB_ForFatScale(Math.abs(comWeight)) + "lb!";
                }
            }
            tv_comp_weight_desc1.setText(getString(R.string.tishi_weight) + weight1Str + getString(R.string.com_fat_desc6) + "," + comWeightStr);
        }
    }

    private void showSettingTipMask() {
        HighLightGuideView.builder(this).setText(getString(R.string.click_to_setting))
                .addNoHighLightGuidView(R.drawable.ic_ok).addHighLightGuidView(setting_menu, 0, 0.5f,
                HighLightGuideView.VIEWSTYLE_CIRCLE)
                .setTouchOutsideDismiss(false).setOnDismissListener(new HighLightGuideView.OnDismissListener() {
            @Override
            public void onDismiss() {
                if (null == UtilConstants.su) {
                    UtilConstants.su = new SharedPreferencesUtil(BodyScaleNewActivity.this);
                }
                UtilConstants.su.editSharedPreferences("lefuconfig", "first_install_setting_pager", "1");
                UtilConstants.FIRST_INSTALL_SETTING_PAGER = "1";
                List<Records> ls = null;
                try {
                    ls = recordService.getAllDatasByScaleAndIDAsc("ce", UtilConstants.CURRENT_USER.getId(), 167f);
                    if (null != ls && ls.size() == 1) {
                        showTipMask();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

        }).show();
    }

    /**
     * 数据对比显示
     *
     * @param record
     */
    private void compData(Records record) {
        LogUtil.e("****compData=数据对比显示======" + record.toString());
        if (Double.parseDouble(record.getCompareRecord()) > 0) {
            tv_comp.setText("↑");
        } else if (Double.parseDouble(record.getCompareRecord()) == 0) {
            tv_comp.setText("-- ");
        } else {
            tv_comp.setText("↓");
        }
        if (record.getComBmi() > 0) {
            tv_comp_bmi.setText("↑");
        } else if (record.getComBmi() == 0) {
            tv_comp_bmi.setText("-- ");
        } else {
            tv_comp_bmi.setText("↓");
        }
    }

    private void showTipMask() {
        HighLightGuideView.builder(this).setText(getString(R.string.click_see_data))
                .addNoHighLightGuidView(R.drawable.ic_ok).addHighLightGuidView(history_menu, 0, 0.5f,
                HighLightGuideView.VIEWSTYLE_CIRCLE)
                .setTouchOutsideDismiss(false).setOnDismissListener(new HighLightGuideView.OnDismissListener() {
            @Override
            public void onDismiss() {
                if (null == UtilConstants.su) {
                    UtilConstants.su = new SharedPreferencesUtil(BodyScaleNewActivity.this);
                }
                UtilConstants.su.editSharedPreferences("lefuconfig", "first_install_bodyfat_scale", "1");
                UtilConstants.FIRST_INSTALL_BODYFAT_SCALE = "1";
                //showHarmBabyTipMask();
            }

        }).show();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(NoRecordsEvent noRecordsEvent) {
        try {
            //Records lastRecords = recordService.findLastRecords(UtilConstants.CURRENT_USER.getId(),"cf");
            localData(null, UtilConstants.CURRENT_USER);
            initBodyBar(UtilConstants.CURRENT_USER, null);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(DeletedRecordsEvent noRecordsEvent) {
        try {
            if (null != noRecordsEvent && null != noRecordsEvent.getLastRecod()) {
                localData(noRecordsEvent.getLastRecod(), UtilConstants.CURRENT_USER);
                initBodyBar(UtilConstants.CURRENT_USER, noRecordsEvent.getLastRecod());
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @OnClick(R.id.harmbaby_menu)
    public void harmBabyMenuClick() {
        try {
            if (null != mScanner) mScanner.stopScan();
            if (null != mBluetoothLeService) {
                mBluetoothLeService.disconnect();
            }

            if (null == babys || babys.size() == 0) babys = uservice.getAllBabys();

            if (null == babys || babys.size() == 0) {
                //添加一个用户组
                startActivity(BabyAddActivity.creatIntent(BodyScaleNewActivity.this, null));
            } else {
                //弹出选择用户组
                startActivity(BabyChoiceActivity.creatIntent(BodyScaleNewActivity.this));
            }
        } catch (Exception e) {
            LogUtil.e("****脂肪秤页面点击抱婴按钮异常==>" + e.getMessage());
        }
    }

    @OnClick(R.id.blue_img)
    public void setBlueToothClick() {
        if (null != mScanner) mScanner.stopScan();
        if (null != mBluetoothLeService) {
            mBluetoothLeService.disconnect();
        }
    }

    @OnClick(R.id.bluetooth_status)
    public void setBlueToothTXClick() {
        if (null != mScanner) mScanner.stopScan();
        if (null != mBluetoothLeService) {
            mBluetoothLeService.disconnect();
        }
    }

    @OnClick(R.id.setting_menu)
    public void setMenuClick() {
        if (null != mScanner) mScanner.stopScan();
        if (null != mBluetoothLeService) {
            mBluetoothLeService.disconnect();
            mBluetoothLeService.close();
        }
        stopBle();
        Intent intent = new Intent(BodyScaleNewActivity.this, SettingActivity.class);
        startActivityForResult(intent, 1);
    }

    @OnClick(R.id.history_menu)
    public void historyMenuClick() {
        if (null == UtilConstants.CURRENT_USER) {
            //调到用户列表选择页面
            Intent intent1 = new Intent();
            intent1.setClass(BodyScaleNewActivity.this, UserListActivity.class);
            BodyScaleNewActivity.this.startActivity(intent1);
        } else {
            startActivityForResult(
                    RecordListActivity.creatIntent(BodyScaleNewActivity.this,
                            UtilConstants.CURRENT_USER), 0);
        }
    }

    @OnClick(R.id.user_header)
    public void userHeaderClick() {
        if (null != mScanner) mScanner.stopScan();
        if (null != mBluetoothLeService) {
            mBluetoothLeService.disconnect();
        }
        //调到用户列表选择页面
        Intent intent1 = new Intent();
        intent1.setClass(BodyScaleNewActivity.this, UserListActivity.class);
        BodyScaleNewActivity.this.startActivity(intent1);
    }

    /**
     * 接收到数据提示
     */
    protected void showReceiveDataDialog() {
        // 初始化自定义布局参数
        LayoutInflater layoutInflater = getLayoutInflater();
        // 为了能在下面的OnClickListener中获取布局上组件的数据，必须定义为final类型.
        View customLayout = layoutInflater.inflate(R.layout.activity_receive_alert,
                (ViewGroup) findViewById(R.id.receiveDataDialog));
        cancleBtn = (Button) customLayout.findViewById(R.id.cancle_datacbtn);
        saveBtn = (Button) customLayout.findViewById(save_databtn);
        cancleBtn.setOnClickListener(imgOnClickListener);
        saveBtn.setOnClickListener(imgOnClickListener);
        receiveDataDialog = new Dialog(this, R.style.dialog);
        receiveDataDialog.setContentView(customLayout);
        receiveDataDialog.show();
        Window window = receiveDataDialog.getWindow();
        window.setGravity(Gravity.CENTER); // 此处可以设置dialog显示的位置
        window.setWindowAnimations(R.style.mystyle); // 添加动画
    }

    /**
     * 询问异常数据是否保存
     */
    protected void askForSaveExceptionData() {
        AlertDialog.Builder builder = new AlertDialog.Builder(BodyScaleNewActivity.this);
        builder.setMessage(getString(R.string.receive_data_waring));
        builder.setNegativeButton(R.string.cancle_btn, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //启动成人用户选择
                LogUtil.e("****启动成人用户选择：" + receiveRecod.toString());
                startActivityForResult(UserChoiceActivity.creatIntent(BodyScaleNewActivity.this, receiveRecod), 103);
                dialog.dismiss();
            }
        });
        builder.setPositiveButton(R.string.ok_btn, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                RecordDao.handleData2(recordService, receiveRecod);
                FitbitHelper.getInstance().postWeightAndFatData(receiveRecod);
                initView();
                dialog.dismiss();
                receiveRecod = null;
            }
        });
        builder.create().show();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            handler.sendEmptyMessage(5);
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_HOME) {
            exit();
            ExitApplication.getInstance().exit(this);
        }
        return super.onKeyDown(keyCode, event);
    }

    /**
     * 退出
     */
    private void exit() {
		/* 停止服务 */
        //stopScanService();
        NotificationManager notificationManager = (NotificationManager)
                getSystemService(android.content.Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(0);
        this.finish();
    }

    @OnClick(R.id.layout_weight_jiantou)
    public void menuWeightOpenClick() {
        if (status_bar2.getVisibility() == View.VISIBLE) {
            status_bar2.setVisibility(View.GONE);
            weight_jiantou.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.down_arrow));
        } else {
            status_bar2.setVisibility(View.VISIBLE);
            weight_jiantou.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.up_arrow));
        }
        if (status_bar_bmi.getVisibility() == View.VISIBLE) {
            status_bar_bmi.setVisibility(View.GONE);
            bmi_jiantou.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.down_arrow));
        }
    }

    @OnClick(R.id.layout_bmi_jiantou)
    public void menuBmiOpenClick() {
        if (status_bar_bmi.getVisibility() == View.VISIBLE) {
            status_bar_bmi.setVisibility(View.GONE);
            bmi_jiantou.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.down_arrow));
        } else {
            status_bar_bmi.setVisibility(View.VISIBLE);
            bmi_jiantou.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.up_arrow));
        }
        if (status_bar2.getVisibility() == View.VISIBLE) {
            status_bar2.setVisibility(View.GONE);
            weight_jiantou.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.down_arrow));
        }
    }

}
